package p7filter;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.*;
import org.apache.lucene.util.Version;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

/**
 * 搜索过滤
 */
public class TestFilter {
    private SearchUtils searchUtils;
    @Before
    public void setUp(){
        searchUtils =new SearchUtils();
    }

    @Test
    public void test1() throws Exception {
        QueryParser parse=new QueryParser(Version.LUCENE_35,"content",new StandardAnalyzer(Version.LUCENE_35));
        Query query=parse.parse("home");

        //过滤出name在【zhangsan,lisi】之间的，true 表示，开闭区间
        //注意下面字段值的顺序不不能颠倒了
        //1,字符串过滤
        Filter filter1=new TermRangeFilter("name","yy","zhangsan",true,true);
        //2，数字过滤
        Filter filter2= NumericRangeFilter.newIntRange("atache",3,5,true,true);
        //3，先搜索，再过滤（和直接搜索有啥区别？），客户端传通配符搜索怎么办？（可以用过滤器过滤掉）
        Filter filter3= new QueryWrapperFilter(new WildcardQuery(new Term("name","*si")));

        searchUtils.searchFilter(query,20,filter2);
    }
}
